$(function(){
	var tipstext = ['确定要删除此运费模版吗？','确定要复制此运费模版吗？'];
//复制模板
	$('.editfreighttemp a.copytemp').each(function(){
		$(this).click(function(){
			copyfreighttemp($(this).attr('tempId'));
		});
	});
	
	function copyfreighttemp(id){
		var _this = $(this);
		showpopbox(tipstext[1]);
		$('.confirmbox ul li a').unbind().click(function(){
			if($(this).hasClass('sure')) {
				console.log('开始复制'+id);
				$.post('/freight/copy/'+id,function(){
					window.location.reload();
				});
			};
			isok();
		});
	};

//删除模版
	$('.editfreighttemp a.deltemp').each(function(){
		$(this).click(function(){
			delfreighttemp($(this).attr('tempId'));
		});
	});
	
	function delfreighttemp(id){
		var _this = $(this),$temptable = _this.parents('.freighttemplist');
		showpopbox(tipstext[0]);
		$('.confirmbox ul li a').unbind().click(function(){
			if($(this).hasClass('sure')) {
				console.log('开始删除'+id);
				$('.freighttemplist').each(function(){
					var this_ = $(this);
					if(this_.parent().find('table').length<1) this_.parent().css('border','0');
				});
				$.post('/freight/del/'+id,function(){
					window.location.reload();
				});
			};
			isok();
		});
	};
	
//弹窗信息
	function showpopbox(txt) {
		$('.overbg').show();
		$('body').append('<div class="popbox"><div class="closepopbox">&times;</div><div class="poptext"><p>'+txt+'</p></div><div class="confirmbox"><ul><li><a href="javascript:;" class="sure">确定</a></li><li><a href="javascript:;" class="cancel">取消</a></li></ul></div></div>');
		$('.closepopbox').unbind().click(function(){
			isok();
		});
	};
	
//关闭弹窗
	function isok(){
		$('.overbg').hide();
		$('.popbox').remove();
	};
	
});
